package action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections4.map.HashedMap;
import com.google.gson.Gson;
import pojo.BaseDataPojo;
import pojo.nationalLine;
import service.nationalLineService;
import serviceImpl.nationalLineServiceImpl;

/**
 * Servlet implementation class nationalLineServlet
 */
@WebServlet("/nationalLineServlet")
public class nationalLineServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
    public nationalLineServlet() {
        super();
        
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String mark = request.getParameter("mark");
		switch(mark) {
		
		case "getNationalLine":   // 获取国家线数据
			getNationalLine(request,response);
			break;
		}
	}


	private void getNationalLine(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		nationalLineService nl = new nationalLineServiceImpl();
		ArrayList<nationalLine> nlList = new ArrayList<nationalLine>();
		nlList = nl.getNationalLine();
		Map<String,ArrayList<nationalLine>> map = new HashedMap<>();
		map.put("nlList",nlList);
		//System.out.println(nlList);
		if(nlList!=null) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<nationalLine>>>("获取nationalLine成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					ArrayList<nationalLine>>>("获取nationalLine为空或失败", false, map)));
		}
		
	}

}
